home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / origami / readfolds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  29.5 KB  |  1,037 lines

  1. /*{{{}}}*/
  2. /*{{{  #includes*/
  3. #ifdef CONFIG_H
  4. #   include "config.h"
  5. #endif
  6.  
  7. #include <sys/types.h>
  8. #include <ctype.h>
  9. #include <limits.h>
  10. #include <unistd.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <stdio.h>
  14.  
  15. #define READFOLDS_C
  16. #define I_DISPLAY_C
  17. #define I_FINDS_C
  18. #define I_FOLDING_C
  19. #define I_GETTK_C
  20. #define I_GETMSG_C
  21. #define I_KEYBOARD_C
  22. #define I_LOOP_C
  23. #define I_MAIN_C
  24. #define I_MESSAGES_C
  25. #define I_MISC_C
  26. #define I_ORIEDT_C
  27. #define I_PROMPT_C
  28. #define I_SCREEN_C
  29. #define I_SHELL_C
  30. #define I_SIGNALS_C
  31. #define I_VIRTUAL_C
  32. #define I_WRITEF_C
  33.  
  34. #include "origami.h"
  35. #include <lib/ori_add_lib.h>
  36. /*}}}  */
  37.  
  38. /*{{{  variables*/
  39. private boolean lang_def;
  40. private boolean tds_crash;
  41. private FILE *rf_tdsfile;
  42. private element *rf_current, *rf_trailing;
  43. private int rf_new_indent;
  44. private unsigned char *rf_dsp_line;
  45. private unsigned char *rf_end_dsp_line;
  46. private int hash_space_leave;
  47. public struct f_sz file_io_size;
  48. /*}}}  */
  49.  
  50. /*{{{  insert_file*/
  51. /*{{{  complain*/
  52. private void complain
  53.  ( msgtyp const x,
  54.    element const * const e,
  55.    element const * const c
  56.  )
  57. {
  58.   unsigned char pos[MSG_LENGTH+32];
  59.   int line;
  60.  
  61.   if (c && e && (line=line_no(e,c)))
  62.      ustrcpy(pos,get_msg(M_Y,line));
  63.   else
  64.      pos[0]='\0';
  65.   warn_message(get_msg(x,pos));
  66. }
  67. /*}}}  */
  68. /*{{{  node handling*/
  69. /*{{{  create_node*/
  70. private void create_node(boolean const txt)
  71. { element *pt;
  72.  
  73.   pt=proc_new_element();
  74.   set_data(pt,rf_dsp_line,txt);
  75.   if (!rf_trailing) pt->indent = rf_new_indent;
  76.   join_links(rf_current, pt);
  77.   rf_current = pt;
  78. }
  79. /*}}}  */
  80. /*{{{  connect_fold*/
  81. private void connect_fold(void)
  82. {
  83.   static element *rf_S;
  84.  
  85.   if (rf_trailing)
  86.    { rf_S = rf_trailing;
  87.      join_links(rf_current, rf_S->x.fold.other_end);
  88.      rf_current = rf_S->x.fold.other_end;
  89.      rf_current->x.fold.other_end = rf_S;
  90.      rf_trailing = rf_S->x.fold.data;
  91.      rf_S->x.fold.data = rf_S->next;
  92.      rf_S->x.fold.other_end = rf_current;
  93.      set_linetyp(*rf_S,get_linetyp(*rf_current));   /*start*/
  94.      /* _fold or _filed */
  95.      current_ind -= rf_S->x.fold.UU.U1.indent;
  96.      set_linetyp(*rf_current,END_FOLD);
  97.      rf_current = rf_S;
  98.    }
  99. }
  100. /*}}}  */
  101. /*{{{  start_a_fold*/
  102. private void start_a_fold(linetyp const start_,int const indent)
  103. {
  104.   set_data(rf_current,rf_dsp_line,False);
  105.   rf_current->x.fold.UU.U1.indent = indent;
  106.   current_ind += indent;
  107.   rf_current->x.fold.data = rf_trailing;
  108.   rf_trailing = rf_current;
  109.   rf_current->x.fold.other_end=proc_new_element();
  110.   set_linetyp(*(rf_current->x.fold.other_end),start_);
  111. }
  112. /*}}}  */
  113. /*}}}  */
  114. /*{{{  read_tds*/
  115. /*{{{  read_stream*/
  116. private void read_stream(int lg)
  117. {
  118.   if (lg>LINELEN)
  119.      tds_crash=True;
  120.   else
  121.    { fread((char*)rf_dsp_line,(size_t)1,(size_t)lg,rf_tdsfile);
  122.      file_io_size.c+=lg;
  123.      rf_dsp_line[lg]=0;
  124.    }
  125.   if (feof(rf_tdsfile))
  126.      tds_crash=True;
  127.   if (tds_crash)
  128.      rf_dsp_line[0]='\0';
  129. }
  130. /*}}}  */
  131. /*{{{  read_tag*/
  132. private int read_tag(int * const vp)
  133. {
  134.   int tag,value;
  135.  
  136.   value = 0;
  137.   do
  138.    /*{{{  read part of the tag*/
  139.    {
  140.      /*{{{  handle breaks and errors*/
  141.      if (aborted)
  142.         tds_crash=True;
  143.      if (tds_crash)
  144.       { tag= -1;
  145.         value=0;
  146.         break;
  147.       }
  148.      /*}}}  */
  149.      /*{{{  get and decode one byte*/
  150.      { int x;
  151.  
  152.        if ((x=getc(rf_tdsfile))==EOF)
  153.         /*{{{  use eof-tag*/
  154.         { tag=2;
  155.           value=1;
  156.           break;
  157.         }
  158.         /*}}}  */
  159.        /*{{{  get tag and combine old and new value*/
  160.        tag=(unsigned char)(x>>6);
  161.        value=(value<<6)+((unsigned char)x&63);
  162.        /*}}}  */
  163.      }
  164.      /*}}}  */
  165.      file_io_size.c++;
  166.    }
  167.    /*}}}  */
  168.   while (tag == 3);
  169.   if (vp)
  170.      *vp=value;
  171.  
  172.   return(tag);
  173. }
  174. /*}}}  */
  175. /*{{{  read_string*/
  176. private void read_string(void)
  177. {
  178.   if (tds_crash)
  179.      rf_dsp_line[0]='\0';
  180.   else
  181.    { int value;
  182.  
  183.      if (read_tag(&value)!=0)
  184.         ustrcpy(rf_dsp_line,i_to_ua(value));
  185.      else
  186.         read_stream(value);
  187.    }
  188. }
  189. /*}}}  */
  190. /*{{{  read_a_list*/
  191. private void read_fold(int,boolean);
  192.  
  193. private void read_a_list(int indent)
  194. { int tag, value;
  195.  
  196.   if (!tds_crash)
  197.      do
  198.       { switch((tag=read_tag(&value)))
  199.          {
  200.            /*{{{  0 = record*/
  201.            case 0:
  202.             { read_stream(value);
  203.               file_io_size.l++;
  204.               create_node(False);
  205.               break;
  206.             }
  207.            /*}}}  */
  208.            /*{{{  2 = function*/
  209.            case 2:
  210.             { switch (value)
  211.                {
  212.                  /*{{{  2 = startfold*/
  213.                  case 2: { read_fold(indent, False);break; }
  214.                  /*}}}  */
  215.                  /*{{{  4 = startfiled*/
  216.                  case 4: { read_fold(indent, True);break; }
  217.                  /*}}}  */
  218.                }
  219.               break;
  220.             }
  221.            /*}}}  */
  222.          }
  223.       }
  224.      while ((tag != 2 || value != 1) && !tds_crash);
  225. }
  226. /*}}}  */
  227. /*{{{  read_fold*/
  228. private void read_fold(int indent,boolean filed)
  229. {
  230.   int t, c, extra_indent;
  231.  
  232.   read_tag((int*)0);   /*startlist*/
  233.   read_string();
  234.   read_tag(&t);
  235.   read_tag(&c);
  236.   read_tag(&extra_indent);
  237.   read_tag((int*)0);   /*should be endlist*/
  238.   file_io_size.l++;
  239.   create_node(False);
  240.   if (filed)
  241.    { start_a_fold(START_FILED, extra_indent);
  242.      read_string();
  243.      rf_dsp_line[_POSIX_PATH_MAX]='\0';
  244.      file_io_size.l++;
  245.      set_data(rf_trailing->x.fold.other_end,rf_dsp_line,False);
  246.    }
  247.   else
  248.    { start_a_fold(START_FOLD, extra_indent);
  249.      read_a_list(indent + extra_indent);
  250.    }
  251.   read_tag((int*)0);   /*endfold or endfiled*/
  252.   file_io_size.l++;
  253.   connect_fold();
  254.   rf_current->x.fold.UU.U1.type = t;
  255.   rf_current->x.fold.UU.U1.contents = c;
  256. }
  257. /*}}}  */
  258.  
  259. private boolean read_tds(unsigned char const * const name)
  260. {
  261.   boolean ret;
  262.   FILE *f;
  263.  
  264.   ret=False;
  265.   tds_crash=False;
  266.   if (rf_tdsfile)
  267.    /*{{{  test, if file is in tds format starts with A0* 80*/
  268.    { f=rf_tdsfile;
  269.      if
  270.       /*{{{  file in tds format(starts with A0* 80)*/
  271.       (    read_tag((int*)&tds_crash)==2
  272.         && tds_crash==0
  273.         && (rf_tdsfile=fopen((char*)name,(char*)"rb"))
  274.       )
  275.       /*}}}  */
  276.       /*{{{  close and read tds*/
  277.       { fclose(f);
  278.         message(get_msg(F_LOADING,name));
  279.         /*{{{  init tds read*/
  280.         tds_crash=False;
  281.         /*{{{  init file_io_size*/
  282.         file_io_size.c=0;
  283.         file_io_size.l=0;
  284.         /*}}}  */
  285.         bd.m.dialect.typ = F_C_TDS;
  286.         /*}}}  */
  287.         read_a_list(0);
  288.         if (tds_crash || fgetc(rf_tdsfile)!=EOF)
  289.          /*{{{  error*/
  290.            complain(M_TDS_CRASH,(element*)0,(element*)0);
  291.          /*}}}  */
  292.         else
  293.          /*{{{  show size of read data*/
  294.            message
  295.             ( get_msg
  296.                ( F_SIZE_FILE,
  297.                  name,
  298.                  "read",
  299.                  file_io_size.l,
  300.                  file_io_size.c
  301.                )
  302.             );
  303.          /*}}}  */
  304.         if (fclose(rf_tdsfile))
  305.            err_message(M_CLOSE_FAILED,name);
  306.         ret=True;
  307.       }
  308.       /*}}}  */
  309.      else
  310.       /*{{{  seek to start*/
  311.       { fseek(f,(off_t)0,SEEK_SET);
  312.         rf_tdsfile=f;
  313.       }
  314.       /*}}}  */
  315.    }
  316.    /*}}}  */
  317.  
  318.   return(ret);
  319. }
  320. /*}}}  */
  321. /*{{{  ascii helps*/
  322. /*{{{  check_hash_stay*/
  323. private int check_hash_stay(unsigned char const *s)
  324. {
  325.   int r=0;
  326.  
  327.   if (*s=='#')
  328.      for(;*++s==' ';r++);
  329.  
  330.   return(r);
  331. }
  332. /*}}}  */
  333. /*{{{  type allowed mark-extension*/
  334. typedef enum
  335.  { S_S_EX=0,  /* "  "         */
  336.    AF_S_EX,   /* "A " or "F " */
  337.    FS_S_EX    /* "F " or "  " */
  338.  } m_ex;
  339. /*}}}  */
  340. /*{{{  find_dialect*/
  341. private boolean find_dialect
  342.  ( unsigned char const * ss,
  343.    unsigned char const * const es
  344.  )
  345. { f_c_types i;
  346.   int lg;
  347.   language_comment *dp;
  348.  
  349.   while (*ss==' ') ss++;
  350.   if (!*ss) return(True);
  351.   lg=es-ss;
  352.   for (i=F_C_NONE,dp=dialects; i<F_C_USER; i++,dp++)
  353.      if
  354.       (    (lg==dp->lg.start)
  355.         && !strncmp((char*)dp->txt.start,(char*)ss,lg)
  356.       )
  357.       { bd.m.dialect.typ=i;
  358.         hash_space_leave=check_hash_stay(ss);
  359.         return(True);
  360.       }
  361.   return(False);
  362. }
  363. /*}}}  */
  364. /*{{{  test_mark*/
  365. private int test_mark
  366.  ( unsigned char const * const str,
  367.    m_ex const ex,
  368.    boolean * const dirty_fold
  369.  )
  370. { int i;
  371.   int the_pos;
  372.   unsigned char *s;
  373.  
  374.   if (!(s=ustrstr(rf_dsp_line,str)))
  375.      return(0);
  376.   the_pos=1+(s-rf_dsp_line);
  377.   if (!the_pos) return(0);
  378.   if (lang_def)
  379.    /*{{{  handle the dialect*/
  380.    { if (!find_dialect(rf_dsp_line,rf_dsp_line+the_pos-1))
  381.       { *dirty_fold=True;return(0); }
  382.      dialects[F_C_USER].lg.start=dialects[bd.m.dialect.typ].lg.start;
  383.      dialects[F_C_USER].lg.end  =dialects[bd.m.dialect.typ].lg.end;
  384.      lang_def=False;
  385.    }
  386.    /*}}}  */
  387.   s=rf_dsp_line+the_pos-1;
  388.   /*{{{  check start-comment*/
  389.   /*{{{  check leading comment string*/
  390.   if
  391.    (    dialects[F_C_USER].lg.start>=the_pos
  392.      || (   dialects[F_C_USER].lg.start
  393.          && strncmp
  394.              ( (char*)(s-dialects[F_C_USER].lg.start),
  395.                (char*)dialects[bd.m.dialect.typ].txt.start,
  396.                dialects[F_C_USER].lg.start
  397.              )
  398.         )
  399.    )
  400.    { *dirty_fold=True;
  401.      return(0);
  402.    }
  403.   /*}}}  */
  404.   /*{{{  check leading spaces/tabs*/
  405.   { unsigned char *t=rf_dsp_line;
  406.     int x=the_pos-1-(dialects[F_C_USER].lg.start);
  407.  
  408.     while (x && *t==' ') { x--;t++; }
  409.     if (x) { *dirty_fold=True;return(0); }
  410.   }
  411.   /*}}}  */
  412.   /*}}}  */
  413.   s+=FOLD_TAG_LENGTH;
  414.   /*{{{  check, if mark is followed by correct 2 letters*/
  415.   if (*s && ex!=S_S_EX)
  416.    { if (*(s+1) && (*(s+1)!=' ')) { *dirty_fold=True;return(0); }
  417.      switch (*s)
  418.       { case 'a':
  419.         case 'A':
  420.            if (ex!=AF_S_EX) { *dirty_fold=True;return(0); }
  421.            *s='A';
  422.            break;
  423.         case 'f':
  424.         case 'F':
  425.            if (ex==S_S_EX) { *dirty_fold=True;return(0); }
  426.            *s='F';
  427.         case ' ':
  428.            break;
  429.         default:
  430.            *dirty_fold=True;
  431.            return(0);
  432.       }
  433.    }
  434.   /*}}}  */
  435.   i=rf_end_dsp_line-s;
  436.   /*{{{  check end-comment*/
  437.   if
  438.    (   dialects[F_C_USER].lg.end
  439.     && (   (i<dialects[F_C_USER].lg.end)
  440.         || ustrcmp
  441.             ( (rf_end_dsp_line-dialects[F_C_USER].lg.end),
  442.               dialects[bd.m.dialect.typ].txt.end
  443.             )
  444.         )
  445.    )
  446.    { *dirty_fold=True;
  447.      return(0);
  448.    }
  449.   /*}}}  */
  450.   *(rf_end_dsp_line-=dialects[F_C_USER].lg.end)='\0';
  451.   rf_dsp_line=(unsigned char*)s;
  452.   return(the_pos-dialects[F_C_USER].lg.start);
  453. }
  454. /*}}}  */
  455. /*}}}  */
  456.  
  457. public void insert_file
  458.  ( element const * const file_ptr,
  459.    element * const prec_ptr,
  460.    element * const next_ptr,
  461.    boolean const remember_file,
  462.    element const * const start_count,
  463.    boolean * const dir_read,
  464.    boolean * const comment_line_ptr,
  465.    FILE * const read_pipe
  466.  )
  467. {
  468.   /*{{{  local variables*/
  469.   FILE *tstorefile;
  470.   boolean filetype_is_dir;
  471.   unsigned char rf_filename[_POSIX_PATH_MAX+1];
  472.   unsigned char dsp_line[LINELEN + _POSIX_PATH_MAX + 3];
  473.   element node;
  474.   element *nf_ptr=0;
  475.   element *ic_ptr=0;
  476.   element *df_ptr=0;
  477.   element *ls_ptr=0;
  478.   element *es_ptr=0;
  479.   /*}}}  */
  480.  
  481.   /*{{{  prepare some variables (pointers, indentation..))*/
  482.   bd.m.dialect.typ=F_C_NONE;
  483.   if (dir_read) *dir_read=False;
  484.   if (comment_line_ptr) *comment_line_ptr=False;
  485.   rf_filename[0]=0;
  486.   node.next=0;
  487.   set_linetyp(node,NOT_FOLD);
  488.   rf_current= &node;
  489.   rf_new_indent=next_ptr->indent;
  490.   if (test_linetyp(*next_ptr,START_OPEN_FOLD))
  491.      rf_new_indent-=next_ptr->x.fold.UU.U1.indent;
  492.   rf_trailing = 0;
  493.   rf_dsp_line = dsp_line;
  494.   current_ind = 0;
  495.   /*}}}  */
  496.   /*{{{  get and check filename*/
  497.   if (!read_pipe)
  498.    { if (!file_ptr)
  499.       /*{{{  use new filename*/
  500.        if (filearg)
  501.         /*{{{  use given one*/
  502.         { ustrcpy(rf_filename,filearg);
  503.           filearg=0;
  504.         }
  505.         /*}}}  */
  506.        else
  507.         {
  508.           /*{{{  maybe use pipename*/
  509. #          ifdef PIPE_FILENAME
  510.              if (start_pipe)
  511.                 ustrcpy(rf_filename,(unsigned char*)PIPE_FILENAME);
  512.              else
  513. #          endif
  514.           /*}}}  */
  515.           /*{{{  else prompt or use default*/
  516.           if (running)
  517.              fileprompt(rf_filename);
  518.           else
  519.            /*{{{  prompt and/or default files*/
  520. #            ifdef DEFAULT_FILE
  521.                 ustrcpy(rf_filename,(unsigned char*)DEFAULT_FILE);
  522. #            else
  523.               { fileprompt(rf_filename);
  524. #               if defined(ALWAYS_START) && defined(OS_NULL_DEVICE)
  525.                    if (!rf_filename[0] && !aborted)
  526.                       ustrcpy(rf_filename,(unsigned char*)OS_NULL_DEVICE);
  527. #               endif
  528.               }
  529. #             endif
  530.            /*}}}  */
  531.           /*}}}  */
  532.         }
  533.       /*}}}  */
  534.      else
  535.       /*{{{  use file-fold-stack name*/
  536.         ustrcpy(rf_filename,get_data(file_ptr));
  537.       /*}}}  */
  538.      if (*rf_filename == '\0' && remember_file)
  539.         exit_origami(bd.m.file_changed_status!=unchanged_file?r_file_nok:r_ok,get_msg(M_BYE));
  540.      if
  541.       (    access((char *)rf_filename,F_OK)==0
  542.         && access((char *)rf_filename,W_OK)==-1
  543.       )
  544.         bd.m.read_only=True;
  545.    }
  546.   title_op(CHGXY);
  547.   /*}}}  */
  548.   if (!aborted)
  549.    { if (!executing_macro)
  550.         enable_abort();
  551.      /*{{{  open file*/
  552.      rf_tdsfile = 0;
  553.      if (read_pipe==(FILE*)0)
  554.       { filetype_is_dir=is_dir((FILE*)0,(char*)rf_filename);
  555.         if (filetype_is_dir)
  556.            tstorefile=0;
  557.         else
  558.            if ((tstorefile=fopen((char *)rf_filename,(char*)"r")))
  559.               rf_tdsfile=tstorefile;
  560.            else
  561.               err_message(M_CANTOPEN,rf_filename);
  562.       }
  563.      /*}}}  */
  564.      /*{{{  read the file*/
  565.      if (read_pipe || bd.e.fold_in || !read_tds(rf_filename))
  566.       /*{{{  read ascii-file*/
  567.       {
  568.         /*{{{  vars for ascii read*/
  569.         boolean null_found=False;
  570.         boolean indent_crash=False;
  571.         boolean dirty_fold=False;
  572.         boolean line_split=False;
  573.         boolean end_space=False;
  574.         int cut_lg=0;
  575.         int f_depth=0;
  576.         unsigned char cut_char=0;
  577.         unsigned char fold_type_str[FOLD_TAG_LENGTH+FOLD_TAG_LENGTH+1];
  578. #        ifdef DIREDT
  579.           boolean reading_dir=False;
  580.           boolean reset_nonfold=False;
  581. #        endif
  582.         /*}}}  */
  583.  
  584.         message(get_msg(F_LOADING,read_pipe?M_PSTR:rf_filename));
  585.         /*{{{  enable language definition parsing*/
  586.         lang_def=True;
  587.         /*}}}  */
  588.         /*{{{  init file_io_size*/
  589.         file_io_size.c=0;
  590.         file_io_size.l=0;
  591.         /*}}}  */
  592.         /*{{{  init local vars*/
  593.         ustrcpy(fold_type_str,bd.f.str.open_f);
  594.         ustrcat(fold_type_str,bd.f.str.close_f);
  595.         bd.m.dialect.typ = F_C_NONE;
  596.         /*}}}  */
  597.         /*{{{  handle directory editing*/
  598.         if (read_pipe)
  599.            tstorefile=read_pipe;
  600.         else
  601.            if (!rf_tdsfile && filetype_is_dir)
  602.             {
  603. #        ifdef DIREDT
  604.               if (rf_filename[0])
  605.                /*{{{  open pipe for dirfold*/
  606.                { unsigned char *match,*nomatch;
  607.                  histories old_default;
  608.  
  609.                  /*{{{  get values for diredit filters*/
  610.                  old_default=overwrite_history_id;
  611.                  overwrite_history_id=match_history;
  612.                  access_history(0,match_history,False,(int*)0,&match);
  613.                  overwrite_history_id=nomatch_history;
  614.                  access_history(0,nomatch_history,False,(int*)0,&nomatch);
  615.                  overwrite_history_id=old_default;
  616.                  /*}}}  */
  617.                  /*{{{  open pipe*/
  618.                  force_sh=True;
  619.                  tstorefile=open_shell
  620.                              ( DIR_CMD
  621.                                 ( rf_filename,
  622.                                   ocl_var[var_dired].v,
  623.                                   match,
  624.                                   nomatch
  625.                                 ),
  626.                                "r"
  627.                              );
  628.                  /*}}}  */
  629.                  reading_dir=True;
  630.                  if (bd.e.fold_in)
  631.                   { bd.e.fold_in=False;
  632.                     reset_nonfold=True;
  633.                   }
  634.                  if (dir_read)
  635.                     *dir_read=True;
  636.                }
  637.                /*}}}  */
  638.               else
  639. #        endif
  640.                  tstorefile=0;
  641.             }
  642.         /*}}}  */
  643.         if (tstorefile)
  644.          /*{{{  read the file*/
  645.          { boolean look_for_att=False;
  646.  
  647.            hash_space_leave=0;
  648.            while (!aborted)
  649.             { boolean hash_moved=False;
  650.               boolean last_space;
  651.               boolean check_line;
  652.  
  653.               /*{{{  read the line*/
  654.               rf_dsp_line=dsp_line;
  655.               *rf_dsp_line=cut_char;
  656.               if
  657.                ( !(fgets((char *)rf_dsp_line+cut_lg,
  658.                          LINELEN+2-bd.f.enter_spaces-rf_new_indent-cut_lg,
  659.                          tstorefile))
  660.                )
  661.                  if (cut_lg)
  662.                     *(rf_dsp_line+cut_lg)='\n';
  663.                  else
  664.                     break;
  665.               /*}}}  */
  666.               /*{{{  check length, cut on '\0', check trailing space/tab*/
  667.               { int line_lg;
  668.  
  669.                 /*{{{  scan line for \n..*/
  670.                 { int i;
  671.                   unsigned char *s;
  672.  
  673.                   /*{{{  move s behind last valid char on the line*/
  674.                   for
  675.                    ( s=rf_dsp_line,
  676.                      i=LINELEN-bd.f.enter_spaces-rf_new_indent,
  677.                      cut_lg=0
  678.                    ;
  679.                    ; i--,
  680.                      s++
  681.                    )
  682.                    { switch (*s)
  683.                       { case '\0':
  684.                            null_found=True;
  685.                         case '\n':
  686.                            break;
  687.                         default:
  688.                            if (i==0)
  689.                             { cut_char= *s;
  690.                               cut_lg=1;
  691.                               line_split=True;
  692.                               break;
  693.                             }
  694.                            continue;
  695.                       }
  696.                      break;
  697.                    }
  698.                   /*}}}  */
  699.                   *(rf_end_dsp_line=s)=0;
  700.                   line_lg=rf_end_dsp_line-rf_dsp_line;
  701.                   last_space=(    line_lg
  702.                                && (    rf_end_dsp_line[-1]==' '
  703.                                     || rf_end_dsp_line[-1]=='\t'
  704.                                   )
  705.                              );
  706.                 }
  707.                 /*}}}  */
  708.                 /*{{{  handle read statistics*/
  709.                 file_io_size.c+=line_lg+1;
  710.                 file_io_size.l++;
  711.                 /*}}}  */
  712.               }
  713.               /*}}}  */
  714.               if (!bd.e.fold_in && lang_def)
  715.                /*{{{  check if current line is a comment-description*/
  716.                { unsigned char *s,*d;
  717.  
  718.  
  719.                  for (s=rf_dsp_line;*s==' ';s++);
  720.                  if ((d=ustrstr(s,fold_type_str)))
  721.                   /*{{{  user defined comment type*/
  722.                   { boolean ok;
  723.                     int marker_pos;
  724.  
  725.                     marker_pos=d-s;
  726.                     /*{{{  set dialect start*/
  727.                     if
  728.                      ((ok=(   (dialects[F_C_USER].lg.start=marker_pos)
  729.                            <= FOLD_COMMENT_LENGTH
  730.                           )
  731.                      ))
  732.                      { d=dialects[F_C_USER].txt.start;
  733.                        while (marker_pos--) *d++ = *s++;
  734.                        *d='\0';
  735.                      }
  736.                     /*}}}  */
  737.                     if (ok)
  738.                      /*{{{  set dialect end*/
  739.                      { s+=(FOLD_TAG_LENGTH+FOLD_TAG_LENGTH);
  740.                        if
  741.                         ((ok=    ((dialects[F_C_USER].lg.end=rf_end_dsp_line-s)
  742.                               <= FOLD_COMMENT_LENGTH)
  743.                         ))
  744.                           ustrcpy(dialects[F_C_USER].txt.end,s);
  745.                      }
  746.                      /*}}}  */
  747.                     if (ok)
  748.                      /*{{{  set this language and continue*/
  749.                      { f_c_types i;
  750.                        language_comment *dp;
  751.  
  752.                        bd.m.dialect.typ = F_C_USER;
  753.                        for (i=0,dp=dialects;i<F_C_USER;dp++)
  754.                           if
  755.                            /*{{{  comments do not match*/
  756.                            (   ustrcmp(dp->txt.start,
  757.                                        dialects[F_C_USER].txt.start)
  758.                             || ustrcmp(dp->txt.end,
  759.                                        dialects[F_C_USER].txt.end)
  760.                            )
  761.                            /*}}}  */
  762.                            /*{{{  test next*/
  763.                              i++;
  764.                            /*}}}  */
  765.                           else
  766.                            /*{{{  set to this one*/
  767.                            { bd.m.dialect.typ=i;
  768.                              break;
  769.                            }
  770.                            /*}}}  */
  771.                        lang_def=False;
  772.                        if (comment_line_ptr) *comment_line_ptr=True;
  773.                        hash_space_leave=check_hash_stay(dialects[F_C_USER].txt.start);
  774.                        continue;
  775.                      }
  776.                      /*}}}  */
  777.                     else
  778.                      /*{{{  reset length of user comment strings*/
  779.                      { dialects[F_C_USER].lg.start=
  780.                        dialects[F_C_USER].lg.end  =0;
  781.                      }
  782.                      /*}}}  */
  783.                   }
  784.                   /*}}}  */
  785.                }
  786.                /*}}}  */
  787.               if (rf_dsp_line[0]=='#')
  788.                /*{{{  handle hash shift*/
  789.                {
  790.                  /*{{{  maybe switch on hash shift*/
  791.                  if
  792.                   (    !bd.m.hash_shift
  793.                     && (    current_ind
  794.                          || (    !lang_def
  795.                               && dialects[bd.m.dialect.typ].txt.start[0]=='#'
  796.                             )
  797.                        )
  798.                   )
  799.                   { bd.m.hash_shift=True;
  800.                     title_op(CHGTITLE);
  801.                   }
  802.                  /*}}}  */
  803.                  if (bd.m.hash_shift)
  804.                   /*{{{  move # to first non-space in line*/
  805.                   { unsigned char *s;
  806.                     int i;
  807.  
  808.                     hash_moved=True;
  809.                     for (*(s=rf_dsp_line)=' ',i=0;*++s==' ';i++);
  810.                     if (i>hash_space_leave)
  811.                        i= -1-hash_space_leave;
  812.                     else
  813.                        i= -1;
  814.                     s[i]='#';
  815.                   }
  816.                   /*}}}  */
  817.                }
  818.                /*}}}  */
  819.               /*{{{  cut current indentation*/
  820.               { int i;
  821.  
  822.                 for (i=current_ind;;i--,rf_dsp_line++)
  823.                    if (i)
  824.                     { if (*rf_dsp_line=='\0')
  825.                          break;
  826.                       else if (*rf_dsp_line!=' ')
  827.                        { indent_crash=True;
  828.                          break;
  829.                        }
  830.                     }
  831.                    else
  832.                       break;
  833.               }
  834.               /*}}}  */
  835.               /*{{{  maybe handle filename- or close-fold-lines*/
  836.               if ((check_line=(!bd.e.fold_in && rf_dsp_line[0])))
  837.                { if
  838.                   (    f_depth
  839.                     && test_mark(bd.f.str.close_f,S_S_EX,&dirty_fold)>0
  840.                   )
  841.                   /*{{{  close-fold*/
  842.                   { f_depth--;
  843.                     connect_fold();
  844.                     look_for_att=False;
  845.                     continue;
  846.                   }
  847.                   /*}}}  */
  848.                  else if
  849.                   (    look_for_att
  850.                     && test_mark(bd.f.str.file_f,AF_S_EX,&dirty_fold)>0
  851.                   )
  852.                   /*{{{  name of filed or attributes*/
  853.                   { boolean ff=(rf_dsp_line[0]=='F');
  854.  
  855.                     if (*(++rf_dsp_line)) rf_dsp_line++;
  856.                     if (ff)
  857.                      /*{{{  filed*/
  858.                      { if (rf_trailing)
  859.                         { rf_dsp_line[_POSIX_PATH_MAX]='\0';
  860.                           set_data(rf_trailing->x.fold.other_end,rf_dsp_line,False);
  861.                         }
  862.                        continue;
  863.                      }
  864.                      /*}}}  */
  865.                     else
  866.                      /*{{{  attibutes*/
  867.                      { if (rf_trailing)
  868.                         { unsigned char *s=rf_dsp_line;
  869.  
  870.                           /*{{{  set type*/
  871.                           rf_trailing->x.fold.UU.U1.type
  872.                              =(unsigned char)atoi((char *)rf_dsp_line);
  873.                           /*}}}  */
  874.                           /*{{{  set contents*/
  875.                           while (*s==' ') s++;
  876.                           while (*s && *s!=' ') s++;
  877.                           rf_trailing->x.fold.UU.U1.contents=
  878.                              (unsigned char)atoi((char *)s);
  879.                           /*}}}  */
  880.                           /*{{{  set data*/
  881.                           while (*s==' ')
  882.                              s++;
  883.                           while (isdigit(*s))
  884.                              s++;
  885.                           if (*s==' ')
  886.                              s++;
  887.                           if (*s)
  888.                            { s[_POSIX_PATH_MAX]='\0';
  889.                              set_data(rf_trailing->x.fold.other_end,s,False);
  890.                            }
  891.                           /*}}}  */
  892.                         }
  893.                        continue;
  894.                      }
  895.                      /*}}}  */
  896.                   }
  897.                   /*}}}  */
  898.                }
  899.               /*}}}  */
  900.               { int the_pos=
  901.                  /*{{{  start fold line?*/
  902.                  ( check_line
  903.                      ? test_mark(bd.f.str.open_f,FS_S_EX,&dirty_fold)
  904.                      : 0
  905.                  );
  906.                  /*}}}  */
  907.  
  908.                 create_node(the_pos<=0);
  909.                 if (the_pos>0)
  910.                  /*{{{  start fold*/
  911.                  { boolean ff=(rf_dsp_line[0]=='F');
  912.  
  913.                    lang_def=False;
  914.                    if (*rf_dsp_line && *(++rf_dsp_line)) rf_dsp_line++;
  915.                    f_depth++;
  916.                    start_a_fold(ff?START_FILED:START_FOLD,the_pos-1);
  917.                    look_for_att=True;
  918.                  }
  919.                  /*}}}  */
  920.                 else
  921.                  /*{{{  text line*/
  922.                  { if (hash_moved)
  923.                     /*{{{  move hash to fold-start*/
  924.                     { unsigned char *s=rf_dsp_line;
  925.  
  926.                       while (*s==' ') s++;
  927.                       if (*s=='#')
  928.                        /*{{{  hash still there, so move back to fold-indentation*/
  929.                        { *s=' ';
  930.                          rf_dsp_line[0]='#';
  931.                          set_data(rf_current,rf_dsp_line,True);
  932.                        }
  933.                        /*}}}  */
  934.                     }
  935.                     /*}}}  */
  936.                    /*{{{  check trailling whitespace*/
  937.                    if (rf_dsp_line[0] && !current_ind && last_space)
  938.                       end_space=True;
  939.                    /*}}}  */
  940.                    look_for_att=False;
  941.                  }
  942.                  /*}}}  */
  943.                 /*{{{  maybe store the line near an read error*/
  944.                 if (dirty_fold && !df_ptr) df_ptr=rf_current;
  945.                 if (null_found && !nf_ptr) nf_ptr=rf_current;
  946.                 if (indent_crash && !ic_ptr) ic_ptr=rf_current;
  947.                 if (line_split && !ls_ptr) ls_ptr=rf_current;
  948.                 if (end_space && !es_ptr) es_ptr=rf_current;
  949.                 /*}}}  */
  950.               }
  951.             }
  952.          }
  953.          /*}}}  */
  954.         /*{{{  check some error-situations on parsed file*/
  955.         if (f_depth)
  956.          /*{{{  autoclose and complain*/
  957.          {
  958.            /*{{{  rf_dsp_line=dsp_line=dialect_start f_depth M_ACF_MSG dialect_end*/
  959.            ustrcpy
  960.             ( dsp_line,
  961.               get_msg(M_ACF_LINE,
  962.                       dialects[bd.m.dialect.typ].txt.start,
  963.                       f_depth,
  964.                       bd.f.str.close_f,
  965.                       dialects[bd.m.dialect.typ].txt.end)
  966.             );
  967.            rf_dsp_line=dsp_line;
  968.            /*}}}  */
  969.            do connect_fold(); while (--f_depth);
  970.            /*{{{  add errormessage and complain*/
  971.            create_node(False);
  972.            complain(M_ACF_MSG,(element*)0,(element*)0);
  973.            /*}}}  */
  974.          }
  975.          /*}}}  */
  976.         /*}}}  */
  977.         /*{{{  maybe reset bd.e.fold_in*/
  978. #        ifdef DIREDT
  979.           if (reset_nonfold) bd.e.fold_in=True;
  980. #        endif
  981.         /*}}}  */
  982.         /*{{{  show size of read data*/
  983.         if (read_pipe || tstorefile)
  984.            message
  985.             ( get_msg
  986.                ( F_SIZE_FILE,
  987.                  (read_pipe?M_PSTR:rf_filename),
  988.                  "read",
  989.                  file_io_size.l,
  990.                  file_io_size.c
  991.                )
  992.             );
  993.         else
  994.            msg_message(M_NEW_FILE);
  995.         /*}}}  */
  996.         /*{{{  close the file*/
  997.         if (   !read_pipe
  998.             && tstorefile
  999.             && (
  1000. #        ifdef DIREDT
  1001.                  reading_dir
  1002.                   ? close_shell(tstorefile)
  1003.                   :
  1004. #        endif
  1005.                     fclose(tstorefile)
  1006.                )
  1007.             )
  1008.               err_message(M_CLOSE_FAILED,rf_filename);
  1009.         /*}}}  */
  1010.       }
  1011.       /*}}}  */
  1012.      /*}}}  */
  1013.      if (!executing_macro)
  1014.         disable_abort();
  1015.    }
  1016.   /*{{{  link the read text to the edited text*/
  1017.   if (node.next)
  1018.    { join_links(prec_ptr, node.next);
  1019.      join_links(rf_current, next_ptr);
  1020.    }
  1021.   /*}}}  */
  1022.   /*{{{  filename must maybe moved to internal data*/
  1023.   if (remember_file)
  1024.    { if (!file_ptr) set_data(prec_ptr,rf_filename,False);
  1025.      set_data(next_ptr,rf_filename,False);
  1026.    }
  1027.   /*}}}  */
  1028.   /*{{{  some error messages for ascii read, put it after linking the read text*/
  1029.   if (df_ptr) complain(M_DIRTY_FOLD,df_ptr,start_count);
  1030.   if (nf_ptr) complain(M_NULL_CRASH,nf_ptr,start_count);
  1031.   if (ic_ptr) complain(M_INDENT_CRASH,ic_ptr,start_count);
  1032.   if (ls_ptr) complain(M_LONG_LINE_SPLIT,ls_ptr,start_count);
  1033.   if (es_ptr) complain(M_TRAIL_SPACE,es_ptr,start_count);
  1034.   /*}}}  */
  1035. }
  1036. /*}}}  */
  1037.